package com.liuli.action;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.liuli.entity.Resume;
import com.liuli.entity.UserInfo;
import com.liuli.service.ResumeService;
import com.liuli.service.UserService;
import com.liuli.utils.ReturnJson;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 基本简历信息控制层
 * @author liyunf
 *
 */
public class ResumeAction extends BaseAction implements ModelDriven<Resume>{
	
	@Autowired
	@Qualifier("resumeService")
	private ResumeService resumeService;
	@Autowired
	@Qualifier("us")
	private UserService userService;
	
	private Resume resume;  //简历基本信息对象
	
	private String nickname;// 用户昵称
	
	private String intro; // 一句话的描述
	
	private String flag;//标记位
	
	
	
	
	/**
	 * 个人简历主页
	 * @return
	 */
	public String index(){
		Integer uid =  (Integer) getSession().get("uid");
		UserInfo userinfo = userService.findById(uid);
		nickname = userinfo.getNickname();
		intro = userinfo.getIntro();
		resume =resumeService.getResumeByUid(uid);
		//第一次注册访问简历需要增加基信息
		if(resume==null){
			resume = new Resume();
			resume.setUid(uid);
			resumeService.save(resume);
			
		}
		return SUCCESS;
	}

	
	/**
	 * 简历自我描述和基本信息内容修改
	 */
	public void edit(){
		JSONObject json = new JSONObject();
		Resume result = resumeService.findById(resume.getRid());
		try {
			if("1".equals(flag)){
				result.setSelfdc(resume.getSelfdc());
			}else if("2".equals(flag)){
				result.setYear(resume.getYear());
				result.setSex(resume.getSex());
				result.setDegree(resume.getDegree());
				result.setWorktime(resume.getWorktime());
				result.setIncity(resume.getIncity());
				result.setTel(resume.getTel());
				result.setEmail(resume.getEmail());
			}else if("3".equals(flag)){
				result.setNowstatu(resume.getNowstatu());
			}
			resumeService.update(result);
			json.put("errcode", 0);
		} catch (Exception e) {
			json.put("errcode", 40014);  //删除失败
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}
	
	
	
	

	public Resume getResume() {
		return resume;
	}


	public void setResume(Resume resume) {
		this.resume = resume;
	}



	public ResumeService getResumeService() {
		return resumeService;
	}



	public void setResumeService(ResumeService resumeService) {
		this.resumeService = resumeService;
	}



	@Override
	public Resume getModel() {
         if(resume==null){
        	 resume = new Resume();
         }
    
		return resume;
	}

	public UserService getUserService() {
		return userService;
	}


	public void setUserService(UserService userService) {
		this.userService = userService;
	}



	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
	
	
	
	

}
